package cn.ibobo.lease.common.util;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: 视图对象工具类
 * Project: meirenhui 
 * ClassName: ListCopyToVOUtil
 * Copyright: Copyright (c) 2017 deshang
 * @author 郭鑫
 * @version 2.0 2017年5月8日下午3:30:34
 */
@Component
public class ListCopyToVOUtil {

	/**
	 * list 实体转视图
	 * @author 郭鑫
	 * @param list
	 * @param clazz
	 * @param <E>
	 * @param <T>
	 * @createDate 2018/5/12 9:31
	 * @return
	 */
	public static <E, T> List<T> getListToVO(List<E> list, Class<T> clazz) {
		List<T> result = new ArrayList<T>();
		if (list != null && !list.isEmpty()) {
			for(E e: list){
				try {
					T vo = clazz.newInstance();
					BeanUtils.copyProperties(e, vo);
					result.add(vo);
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		}
		return result;
	}

}
